<?php
/**
 * Person Name Validator
 * I was using the Alpha validator for people's names but that doesn't allow
 * things like "Jr." and stuff. This is a more liberal rule.
 *
 * @package     Visi
 * @subpackage  Validation Rules
 * @author      Luke Visinoni <luke.visinoni@gmail.com>
 * @copyright   (c) 2010 Luke Visinoni <luke.visinoni@gmail.com>
 * @version     $Id$
 */
class Visi_Rule_PersonName extends Q_Rule_Abstract {

    /**
     * The parameters that were passed to this rule
     * @todo It would probably be useful to add params for things like
     * "whitespace", "commas", "periods", etc. but for now I'll just allow all
     * of them.
     */
    protected $_params = array(
        'apostrophe' => true,
        'whitespace' => true,
        'period' => true,
        'comma' => true,
        'dash' => true,
    );
    
    public function isValid($value) {
    
        $apostrophe = "";
        $whitespace = "";
        $period = "";
        $comma = "";
        $dash = "";
        if ($this->getParam('apostrophe')) {
            $apostrophe = "'";
        }
        if ($this->getParam('whitespace')) {
            $whitespace = "\s";
        }
        if ($this->getParam('period')) {
            $period = "\.";
        }
        if ($this->getParam('comma')) {
            $comma = ",";
        }
        if ($this->getParam('dash')) {
            $dash = "-";
        }
        $pattern = "/^[a-z{$comma}{$period}{$whitespace}{$apostrophe}{$dash}]+$/i";
        return $this->_validatePattern($pattern, $value);
    
    }

}
